//
//  LeftMenuHeadView.swift
//  Order
//
//  Created by Lazyloading on 2020/7/21.
//  Copyright © 2020 lazyloading. All rights reserved.
//

import UIKit

class LeftMenuHeadView: UIView {

    var rechargeBlock : ((UIButton)->())?
    
    lazy var titleLabel: UILabel = {
        let label = UILabel.init();
        label.font = UIFont.init(fontType: .regular, fontSize: 16);
        label.textColor = .white;
        label.text = "余额：";
        return label;
    }()
    
    lazy var moneyLabel: UILabel = {
        let label = UILabel.init();
        label.font = UIFont.init(fontType: .medium, fontSize: 20);
        label.textColor = .white;
        label.text = "9000.00";
        return label;
    }()
    
    lazy var rechargeBtn: UIButton = {
        let button = UIButton.init();
        button.addTarget(self, action: #selector(rechargeAction(button:)), for: .touchUpInside);
        button.setTitle("充值", for: .normal);
        button.titleLabel?.font = UIFont.init(fontType: .regular, fontSize: 15);
        button.setTitleColor(.white, for: .normal);
        button.layer.cornerRadius = 15;
        button.layer.masksToBounds = true;
        button.layer.borderColor = UIColor.white.cgColor;
        button.layer.borderWidth = 0.8;
        return button;
    }()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        
        self.loadDefaultSetting();
        self.initSubViews();
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func rechargeAction(button : UIButton){
        ZMLog("充值");
        if self.rechargeBlock != nil{
            self.rechargeBlock!(button);
        }
    }
    
    //    MARK: 🐷 加载默认设置 🐷
    private  func loadDefaultSetting()  {
        
    }
    //    MARK: 🐷 初始化子视图 🐷
    private  func initSubViews()  {
        self.addSubview(self.titleLabel);
        self.addSubview(self.moneyLabel);
        self.addSubview(self.rechargeBtn);
        
        self.titleLabel.snp.makeConstraints { (make) in
            make.leading.equalToSuperview().offset(15);
            make.bottom.equalTo(self.moneyLabel.snp.top).offset(-3);
        };
        
        self.moneyLabel.snp.makeConstraints { (make) in
            make.leading.equalTo(self.titleLabel);
            make.centerY.equalTo(self.rechargeBtn);
        };
        
        self.rechargeBtn.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview().offset(-10);
            make.width.equalTo(65);
            make.trailing.equalToSuperview().offset(-15);
            make.height.equalTo(30);
        };
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews();
    }
}
